use bevy::prelude::States;
use bevy::state::state::FreelyMutableState;
use nanomachine::Machine;

#[derive(Debug, Clone, PartialEq, Eq, Hash,Default)]
pub enum GameState {
    #[default]
    NotStarted,
    Playing,
    Paused,
    Ended,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Event {
    Start,
    Pause,
    Resume,
    GameOver,
    ReturnMain,
}

pub struct MyGame {
    machine: Machine<GameState,Event>,
}
impl Default for MyGame {
    fn default() -> Self {
        let mut machine = Machine::new(GameState::NotStarted);
        machine.when_iter(Event::Start,[(
            GameState::NotStarted, GameState::Playing),
            (GameState::Ended, GameState::Playing),
            (GameState::Paused, GameState::Playing)]);
        machine.when(Event::Pause,GameState::Playing,GameState::Paused);
        machine.when(Event::Resume,GameState::Paused,GameState::Playing);
        machine.when(Event::GameOver,GameState::Playing,GameState::Ended);
        machine.when_iter(Event::ReturnMain,[
            (GameState::Paused,GameState::NotStarted),
            (GameState::Ended,GameState::NotStarted),]);
        MyGame { machine }
    }
}


impl States for GameState {}

impl FreelyMutableState for GameState {}